
const dataProd = () => {

}

// 此文件保存reducer中公用的方法
dataProd.prototype.findNodeByName = (data, name, newValue = null) => {
  console.log(data,name)
  if (!!data) {
    let obj = null;
    if (isObjectFn(data)) {
      if (data.name1 === name) {
        if (newValue) {
          data = newValue;
          return data;
        }
        return data;
      } else {
        if (data.children && data.children.length) {
          obj = dataProd.prototype.findNodeByName(data.children, name, newValue || null);
          if (!!obj) {
            return obj;
          }
        }
      }
    } else {
      for (let i = 0; i < data.length; i++) {
        if (data[i].name1 === name) {
          if (newValue) {
            data[i] = newValue;
            return data[i];
          }
          return data[i];
        } else {
          if (data[i].children && data[i].children.length) {
            obj = dataProd.prototype.findNodeByName(data[i].children, name, newValue || null);
            if (!!obj) {
              return obj;
            }
          }
        }
      }
      return obj;
    }
  }
};

exports.dataProd = dataProd;
// 判断数组
export const isArrayFn = (o) => {
  return Object.prototype.toString.call(o) === "[object Array]";
};
// 判断对象
export const isObjectFn = (o) => {
  return Object.prototype.toString.call(o) === "[object Object]";
};